<template>
	<view class="book-container mainpadding mainbgc" v-show="show">

		<view class="mainpadding ffffff border-r2">
			<view class="title same">{{dataAll.tour_ticket.name}}</view>
			<view class="same count flexleft">
				<text>预订份数</text>
				<u-number-box v-model="value" @change="valChange"></u-number-box>
			</view>
		</view>
		<view class="ffffff margin-top border-r2">
			<view class="same mainpadding">联系人信息</view>
			<view class="info mainpadding">
				<text>联系人</text>
				<input type="text" placeholder="请填写真实姓名" v-model="username">
			</view>
			<view class="info mainpadding">
				<text>手机号</text>
				<input type="text" placeholder="请输入联系人手机号" v-model="mobile">
			</view>
		</view>
		<view class="mainpadding ffffff border-r2 margin-top">
			<view class="same">预订须知</view>
			<view class="announce">{{dataAll.ticket_xz}}</view>
		</view>
		<view class="bottom-box">
			<view class="pAb">
				<view class="price">￥{{allprice}}</view>
				<view class="btn-box" >
					<view class="yDBtn" @click="toBook()">立即预订</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				value: 1,
				listid: "",
				dataAll: {},
				username:"",
				mobile:"",
				show:false,
			}
		},
		computed:{
			allprice(){
				return this.value * this.dataAll.pay_price
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.init()
		},
		methods: {
			init() {
				httpRequest.request('api/tourorder/sure', 'GET', {
					tour_ticket_id: this.listid,
					num: 1
				}, false, false, false).then(res => {
					this.show=true
					this.dataAll = res.data
				}).catch(err => {
					this.show=true
					httpRequest.toast(err.msg);
				})
			},
			valChange(e) {
				console.log('当前值为: ' + e.value)
			},
			toBook() {
				if(this.username==""){
					httpRequest.toast("请输入联系人姓名")
					return false
				}
				if(this.mobile==""){
					httpRequest.toast("请输入联系人手机号")
					return false
				}
				if (!this.mobile.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码");
					return false;
				}
				httpRequest.request('api/tourorder/create_order', 'GET', {
					tour_ticket_id: this.listid,
					num: this.value,
					username: this.username,
					mobile: this.mobile
				}, false, false, false).then(res => {
					if(res.code==1){
						let data = {
							id:res.data.id,
							pay_price:res.data.pay_price,
							type:2,
							allscore:res.data.allow_score
						}
						uni.redirectTo({
							url: '/pages/scenic/lijizf?msg=' + encodeURIComponent(JSON.stringify(data))
						})
					}else{
						httpRequest.toast(res.msg);
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.same {
		font-size: 30rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.title {
		margin-bottom: 30rpx;
	}

	.count {
		justify-content: space-between;

		text {
			font-weight: 500;
		}
	}

	.info {
		display: flex;

		text {
			margin-right: 58rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #333333;
		}
	}

	.announce {
		margin-top: 30rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.bottom-box {
		position: fixed;
		bottom: 30rpx;
	}

	.pAb {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: calc(100vw - 60rpx);
	}

	.price {
		font-size: 48rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FF5C00;
		line-height: 52rpx;
	}

	.yDBtn {
		border-radius: 120rpx;
		background-color: #FF5C00;
		padding: 2rpx 84rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
		line-height: 80rpx;
	}
</style>
